import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

class PageWebView extends StatefulWidget {
  String _url;
  String _title;

  static Future<void> start(BuildContext context, String url,
      {String title}) async {
    return await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) {
          return PageWebView(url, title);
        },
      ),
    );
  }

  @override
  State<StatefulWidget> createState() => _PageWebView();

  PageWebView(this._url, this._title) : assert(_url != null);
}

class _PageWebView extends State<PageWebView> {
  WebViewController _webViewController;

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          leading: TextButton(
            child: Icon(
              Icons.arrow_back,
              color: Colors.white,
              size: 20,
            ),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
          title: Text(
            "${widget._title}",
            style: TextStyle(
              color: Colors.white,
            ),
          ),
          centerTitle: true,
        ),
        body: WebView(
          initialUrl: "${widget._url}",
          javascriptMode: JavascriptMode.unrestricted,
          onWebViewCreated: (WebViewController webViewController) {
            _webViewController = webViewController;
          },
          onProgress: (int progress) {
            print("onProgress====$progress%");
          },
          onPageStarted: (String url) {
            print("onPageStarted====$url");
          },
          onPageFinished: (String url) {
            print("onPageFinished====$url");
          },
          gestureNavigationEnabled: true,
        ),
      );
}
